<?php
declare (strict_types = 1);

namespace app\model;

use think\facade\Config;

/**
 * @mixin \think\Model
 * 轮播图
 */
class Carousel extends Base
{
    protected $schema = [
        "id" => "int",  // 编号
        "title" => "varchar",  // 标题
        "picture" => "varchar",  // 图片
        "movie" => "varchar",  // 视频地址
        "thumb" => "varchar",  // 缩略图片
        "type" => "tinyint", // 类型, 0 图片, 1 视频
        "url" => "varchar",  // 链接地址
        "sort" => "mediumint",  // 排序, 数字越大越靠前
        "status" => "tinyint",  // 状态
        "summary" => "varchar",  // 备注
        "create_time" => "datetime",  // 创建时间
        "update_time" => "datetime",  // 更新时间	
    ];
    
    public static function queryPage($params = [])
    {
        $limit = empty($params['limit']) ? Config::get('app.page_size', 20) : (int)$params['limit'];
            $list = self::field('id,title,picture,thumb,type,url,sort,status,summary,create_time,update_time')
            ->order('id desc')->paginate(['list_rows'=>$limit, 'query' => $params]);

        return $list;
    }

    public static function getCarousel($limit = 10)
    {
        return self::where('status', 1)->order('sort desc, id desc')->limit($limit)->select();
    }
}
